package com.syys.qa.service.impl;

import java.util.List;

import com.syys.common.config.WeCatConfig;
import com.syys.common.json.JSONObject;
import com.syys.common.utils.DateUtils;
import com.syys.common.utils.IpUtils;
import com.syys.common.utils.ShiroUtils;
import com.syys.qa.util.UrlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.syys.qa.mapper.QaThemeMapper;
import com.syys.qa.domain.QaTheme;
import com.syys.qa.service.IQaThemeService;
import com.syys.common.core.text.Convert;

/**
 * 问卷主题Service业务层处理
 *
 * @author ys
 * @date 2021-07-01
 */
@Service
public class QaThemeServiceImpl implements IQaThemeService {
    @Autowired
    private QaThemeMapper qaThemeMapper;

    /**
     * 查询问卷主题
     *
     * @param themeId 问卷主题ID
     * @return 问卷主题
     */
    @Override
    public QaTheme selectQaThemeById(Long themeId) {
        return qaThemeMapper.selectQaThemeById(themeId);
    }

    /**
     * 查询问卷主题列表
     *
     * @param qaTheme 问卷主题
     * @return 问卷主题
     */
    @Override
    public List<QaTheme> selectQaThemeList(QaTheme qaTheme) {
        return qaThemeMapper.selectQaThemeList(qaTheme);
    }

    /**
     * 新增问卷主题
     *
     * @param qaTheme 问卷主题
     * @return 结果
     */
    @Override
    public int insertQaTheme(QaTheme qaTheme) {
        qaTheme.setCreateTime(DateUtils.getNowDate());
        int i = qaThemeMapper.insertQaTheme(qaTheme);
        if (i > 0) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("themeId", qaTheme.getThemeId());
            String s = UrlUtil.enCryptAndEncode(jsonObject.toString());
            String str = "http://39.103.230.254/qa?q=" + s;
            qaTheme.setThemeUrl(str);
        }
        qaTheme.setUpdateBy(ShiroUtils.getLoginName());
        qaThemeMapper.updateQaTheme(qaTheme);
        return i;
    }

    /**
     * 修改问卷主题
     *
     * @param qaTheme 问卷主题
     * @return 结果
     */
    @Override
    public int updateQaTheme(QaTheme qaTheme) {
        qaTheme.setUpdateTime(DateUtils.getNowDate());
        return qaThemeMapper.updateQaTheme(qaTheme);
    }

    /**
     * 删除问卷主题对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteQaThemeByIds(String ids) {
        return qaThemeMapper.deleteQaThemeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除问卷主题信息
     *
     * @param themeId 问卷主题ID
     * @return 结果
     */
    @Override
    public int deleteQaThemeById(Long themeId) {
        return qaThemeMapper.deleteQaThemeById(themeId);
    }
}
